package com.amos.util;

import java.util.Collection;
import java.util.Map;
import java.util.UUID;

/**
 * Copyright © 2018 嘉源锐信. All rights reserved.
 *
 * @Project: mu-exam
 * @ClassName: StringUtils
 * @Package: com.amos.util
 * @author: zhuqb
 * @Description: 字符类型操作类
 * @date: 2020/3/3 0003 下午 17:20
 * @Version: V1.0
 */
public class StringUtils {
    /**
     * 判断对象是否为空
     *
     * @param object 被判断的对象
     * @return true 为空 false 不为空
     */
    public static boolean isNullOrEmpty(Object object) {
        if (null == object) {
            return true;
        }
        if (object instanceof String) {
            return "".equals((String) object)
                    || "null".equalsIgnoreCase((String) object) ? true : false;
        } else if (object instanceof Collection) {
            return ((Collection) object).size() == 0 ? true : false;
        } else if (object instanceof Map) {
            return ((Map) object).size() == 0 ? true : false;
        }

        return false;
    }

    /**
     * 判断是否不为空
     *
     * @param object 判断的对象
     * @return true 不为空 false 为空
     */
    public static boolean isNotNullOrEmpty(Object object) {
        return !isNullOrEmpty(object);
    }

    /**
     * 生成UUID
     *
     * @return
     */
    public static String generateUuid() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }


    /**
     * 首字母转小写
     *
     * @param s
     * @return
     */
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0))) {
            return s;
        } else {
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
        }
    }

    /**
     * 首字母转大写
     *
     * @param s
     * @return
     */
    public static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0))) {
            return s;
        } else {
            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
        }
    }

    /**
     * 是否包含字符串
     *
     * @param str  验证字符串
     * @param strs 字符串组
     * @return 包含返回true
     */
    public static boolean inStringIgnoreCase(String str, String... strs) {
        if (str != null && strs != null) {
            for (String s : strs) {
                if (str.equalsIgnoreCase(trim(s))) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 去空格
     */
    public static String trim(String str) {
        return (str == null ? "" : str.trim());
    }
}
